<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <!-- 输入框 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" @change='ChangeEnder' clearable>
            <el-button slot="append" icon="el-icon-search" @click="ChangeEnder"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary">添加列表</el-button>
        </el-col>
      </el-row>
      <!-- tab列表区域 -->
      <el-table :data="queryGoodsList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="商品名称" prop="goods_name"></el-table-column>
        <el-table-column label="商品价格(元)" prop="goods_price"></el-table-column>
        <el-table-column label="商品重量" prop="goods_weight"></el-table-column>
        <el-table-column label="创建时间" prop="add_time">
          <template slot-scope="scope">
            {{scope.row.add_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 50, 150, 400]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      // 总数
      total: 0,
      queryGoodsList: []
    }
  },
  created() {
    this.goodsList()
  },
  methods: {
    async goodsList() {
      let { data: res } = await this.$http.get('goods', {
        params: { ...this.queryInfo }
      })
      console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      this.total = res.data.total
      this.queryGoodsList = res.data.goods
    },
    // 每页多少条数据
    handleSizeChange(val){
      this.queryInfo.pagesize=val
      this.goodsList()
    },
    // 第几页数据
    handleCurrentChange(val){
      this.queryInfo.pagenum=val
      this.goodsList()
    },
    // input事件
    ChangeEnder(){
       this.goodsList()
    }
  }
}
</script>
<style lang="less" scoped>
</style>
